#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
day 24 homework
"""
# 1.计算任意一个文件夹的大小（考虑绝对路径的问题）
# 基础需求
# 这个文件夹中只有文件
# 进阶需求
# 这个文件夹中可能有文件夹，并且文件夹中还可能有文件夹...不知道有多少层
"""
import os
import sys


def find(pattern, directory):
    pattern = pattern.lower()
    flag = False
    for (a, b, c) in os.walk(directory):
        for item in b:
            if pattern == item.lower():
                found = os.path.join(a, item)
                flag = True
    if flag:
        return found
    else:
        sys.exit('文件夹不存在')


directory = input('输入搜索的盘符(c/d):')
pattern = input('输入文件夹名:')
found = find(pattern, directory + ':\\')

total = os.path.getsize(found)
for a, b, c in os.walk(found):
    for item in c:
        path = os.path.join(a, item)
        total += os.path.getsize(path)
print('%sKB' % (total / 1024).__round__(2))
"""

# 2.校验大文件的一致性
# 基础需求
# 普通的文字文件
# 进阶需求
# 视频或者是图片
"""
import os
import hashlib
path1 = r'G:\code\project1\project1.py'
path2 = r'G:\code\project1\project1-副本.py'
def hash_md5(path):
    a = os.path.getsize(path)
    with open(path, 'rb') as f:
        d = 0
        md5 = hashlib.md5()
        while a > d:
            d += 100000000
            md5.update(f.read(100000000))
        data = md5.hexdigest()
    return data
data1 = hash_md5(path1)
data2 = hash_md5(path2)
if data1 == data2:
    print('文件一致')
else:
    print('文件不一致')
"""
# 3.发红包
# 每一个人能够抢到的金额的概率都是平均的
"""
import random

red_packet = input('你要发的红包数量:')
"""
# 4.根据代码研究super和mro的关系
"""
class A:
    def func(self):
        print('in a')

class B(A):
    def func(self):
        print('in b')
        super().func()

class C(A):
    def func(self):
        print('in c')
        super().func()

class D(B,C):
    def func(self):
        print('in d')
        super().func()

d = D()
d.func()
# in d
# in b
# in c
# in a
"""
